<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>更新票号updateCabinUpdateNum</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		#main{
			width:500px;
			height:240px;
			text-align:right;
			overflow:auto;
		}
		
		#main p:nth-of-type(1){
			margin-top:20px;
		}
		#main input{
			border:1px solid #e6e6e6;
			border-radius:2px;
			width:200px;
			height:24px;
			margin-top:10px;
			outline:none;
			margin-left:5px;
			padding-left:5px;
		}
		#btnBox{
			text-align:center;
			padding-top:10px;
		}
		button{
			width:90px;
			height:28px;
			background:#00aa98;
			border:none;
			color:white;
			cursor:pointer;
			margin:0 20px;
		}
		
	</style>
	<body>
		<div id='main'>
												
		</div>		
		<div id='btnBox'>
			<button class='sure'>确定</button>
			<button class='cancle'>取消</button>
		</div>
	</body>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
		<script type="text/javascript" src="../js/common.js" ></script>
		<script>
		//____________________________________________________________________数据渲染
			var postUpdateNumJson = parent.postUpdateNumJson;
			var passengerNameArr = postUpdateNumJson.passengerName;
			var certificateNumberArr = postUpdateNumJson.certificateNumber;
			var ticketNumberArr = postUpdateNumJson.ticketNumber;
			console.log(certificateNumberArr.length)
			for(var i=0;i<certificateNumberArr.length;i++){
				var ticketNumber=ticketNumberArr[i]?ticketNumberArr[i]:"";				
				var str = "";
				str+="<p>"+
						 "<span class='passengerName'>"+
						 	"<span class='passengerName1'>"+passengerNameArr[i]+"</span>"+
						 	"<span>(<span class='certificateNumber'>"+certificateNumberArr[i]+"</span>)</span>"+
						 "</span>"+
						 "<span>"+
						 	"<input class='ticketNumber' type='text' value="+ticketNumber+">"+
						 "</span>"+
					 "</p>"
				$("#main").append(str)
			}
			
		
		//_____________________________________________________________________放上鼠标显示证件号
			/* $(".passengerName").hover(function(){
				$(this).parent().find("span[class=certificateNumber]").show()
			},function(){
				$(this).parent().find("span[class=certificateNumber]").hide()
			}) */
		//_____________________________________________________________________提交数据	
			$(".sure").click(function(){
				var postMess = [];
				var len = $(".passengerName").length;
				var orderId = parent.$(".orderNo").text();
				for(var i=0;i<len;i++){
					var json = {};
					json.orderId = orderId;
					json.passengerName = $(".passengerName1").eq(i).text();
					json.certificateNumber = $(".certificateNumber").eq(i).text();
					//var ticketNumber = $(".ticketNumber").eq(i).val();
					if(!/^\d{3}(\-\d+)?\d{1,}$/.test($(".ticketNumber").eq(i).val())||$(".ticketNumber").eq(i).val().length>18){
						layer.msg("票号格式不正确",{icon:2,time:1500});
						return false;
					}else{
						json.ticketNumber = $(".ticketNumber").eq(i).val();
					}
					
					postMess.push(json);
				}
				layer.msg('更新票号中...', {icon: 16,shade: 0.01});
				$.ajax({
					type:"post",
					url:"../orderAddon/updExchTkt?temp="+Math.random(),
					contentType:'application/json;charset=utf-8',
					data:JSON.stringify(postMess),
					async:true,
					success:function(data){
						data = JSON.parse(data)
						if(data.status=="1001"){
							layer.msg('更新票号成功', {icon: 1,time:1000},function(){
								closeWin()
							});			
						}else{							
							layer.alert("更新票号失败——"+data.message);
						}
					}
				});
			})
		//______________________________________________________________________取消按钮
			$(".cancle").click(function(){
				closeWin()
			})
		</script>			
</html>
